package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

import java.util.ArrayList;
import java.util.List;

class PascalsTriangleIi {
    // 2022-08-31 10:05:52
    public static void main(String[] args) {
        Solution solution = new PascalsTriangleIi().new Solution();
        solution.getRow(3);
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public List<Integer> getRow(int rowIndex) {
            List<List<Integer>> list = new ArrayList<>();
            List<Integer> rowOne = new ArrayList<>();
            rowOne.add(1);
            List<Integer> rowTwo = new ArrayList<>();
            rowTwo.add(1);
            rowTwo.add(1);
            list.add(rowOne);
            list.add(rowTwo);
            for (int i = 2; i <= rowIndex; i++) {
                List<Integer> row = new ArrayList<>();
                for (int j = 0; j <= i; j++) {
                    if (j == 0) {
                        row.add(j, list.get(i - 1).get(j));
                    } else if (j == i) {
                        row.add(j, list.get(i - 1).get(j - 1));
                    } else {
                        row.add(j, list.get(i - 1).get(j) + list.get(i - 1).get(j - 1));
                    }
                }
                list.add(row);
            }
            return list.get(rowIndex);
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}